package com.hs.hlw.credit.system.data.util;

import com.hs.hlw.credit.system.common.enumeration.DataBaseType;
import com.hs.hlw.credit.system.data.primary.model.DataSource;
import com.hualongdata.exception.BusinessException;

/**
 * DbUtil
 * @author zhb
 * @date 2018/11/30
 */
public class CommonDataUtil {
    /**
     * 获取数据库工具类实例
     * @param dataBaseType
     * @param url
     * @param userName
     * @param password
     * @return
     */
    public static DbUtil getDbUtilInstance(Short dataBaseType, String url, String userName, String password) {
        DataBaseType type = DataBaseType.getDataBaseTypeByCode(dataBaseType);
        DbUtil dbUtil = null;
        switch (type) {
            case TYPE_2:
                dbUtil = DbUtil_DM.getInstance(url, userName, password);
                break;
            default:
                throw new BusinessException("暂时不支持" + type.value + "数据库");
        }
        return dbUtil;
    }

    /**
     * 获取数据库工具类实例
     * @param dataSource
     * @return
     */
    public static DbUtil getDbUtilInstance(DataSource dataSource) {
        return getDbUtilInstance(dataSource.getDatabaseType(), dataSource.getJdbcUrl(), dataSource.getUserName(), dataSource.getPassword());
    }
}